package ie.lawlor.amvc.component.log4j;

import ie.lawlor.amvc.event.Event;
import ie.lawlor.amvc.patterns.standard.StandardModel;

import org.apache.log4j.xml.DOMConfigurator;



public class Log4jModel extends StandardModel {
    String filename;
    /** Creates a new instance of LoginModel */
    public Log4jModel(String name) {
    	super(name);
    }
    

	public void doReadConfig(Event event) {
		String home = System.getProperty("user.home");
		if (home == null) {
			System.out.println("About to read "+ "./config/" + filename);
			DOMConfigurator.configureAndWatch("./config/" + filename);
		} else {
			System.out.println("About to read "+ home + "/config/" + filename);
			DOMConfigurator.configureAndWatch(home + "/config/" + filename);
		}

		fire(Log4jController.CONFIG_READ);
    }
    
    public void doSetFilename(Event e){
    	filename = (String)e.getPayload();
    }
    
}
